﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DriveBeamEditor.Controls.General.Data
{
    public partial class DynamicTreeList : Control
    {
        #region Fields

        private readonly TreeNode _tree = new TreeNode("Root", null);

        #endregion

        #region Properties

        public TreeNode Tree { get { return _tree; } }

        #endregion

        #region CTORs

        public DynamicTreeList()
        {
            InitializeComponent();

            Tree.ParentChanged += Tree_ParentChanged;
            Tree.ChildAdded += Tree_ChildAdded;
            Tree.ChildRemoved += Tree_ChildRemoved;
        }


        #endregion

        #region Events

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
        }

        void Tree_ParentChanged(object sender, TreeNode e)
        {
            var node = sender as TreeNode;
            MessageBox.Show(string.Format(
                "Node '{0}' has changed parent to '{1}'",
                (node != null ? node.Name : "?"),
                (e != null ? e.Name : "ROOT"))
            );
        }

        void Tree_ChildAdded(object sender, TreeNode e)
        {
            var parent = sender as TreeNode;
            MessageBox.Show(string.Format(
                "Node '{0}' is now a child of '{1}'",
                (e != null ? e.Name : "?"),
                (parent != null ? parent.Name : "ROOT"))
            );
        }

        void Tree_ChildRemoved(object sender, TreeNode e)
        {
            var parent = sender as TreeNode;
            MessageBox.Show(string.Format(
                "Node '{0}' is no longer a child of '{1}'",
                (e != null ? e.Name : "?"),
                (parent != null ? parent.Name : "ROOT"))
            );
        }

        #endregion

        #region Methods

        #endregion
    }
}
